package app.netant.finishbook.x555;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class X555Detail extends BaseDetail {

	public X555Detail(String netSite) {
		super(netSite);
		this.preHref = "http://www.555x.org";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".d1 .down .xiazai .shutou h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("TXT");
			if(idx>0){
				title = title.substring(0,idx);
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".d1 .down .xiazai .xinxi .shuji ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".d1 .down .xiazai .zhangjie");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		String location = this.netSite;
		int ed = this.netSite.lastIndexOf(".");
		int st = this.netSite.lastIndexOf("/");
		if(st>0 && ed>0 && ed>st){
			String plus = location.substring(st+1,ed);
			String href = "http://www.555x.org/home/down/txt/id/"+plus.substring(3);
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
		
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".d1 .dq .wz a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		X555Detail detail = new X555Detail("http://www.555x.org/html/xuanhuan/txt45408.html");
		detail.test();
	}



}
